<%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<script type="text/javascript">
var userCode ;
var begin ;
var end
$(document).ready(function() {
	$('#outxls').click(function(){
		exprotData();
	});

			
	$('#recordYcList').datagrid({
		fit: true,
		title:'',
		nowrap: false,
		striped: true,
		singleSelect: true,
		sortName: 'BROWSETIME',
		sortOrder: 'desc',
		frozenColumns: [[  
			{field:'BROWSETIME',title:'异常上网时间',width:120},
		]],
		columns: [[
			{field:'TITLE',title:'网页标题',width:320},
		    {field:'TYPENAME',title:'类型',width:60},
			{field:'URL',title:'网页地址',width:420}
		]], 
		pageSize: 20,
		pagination: true,
		rownumbers: true,
		onClickRow:function(rowIndex, rowData) {
			$('#recordYcList').datagrid('clearSelections').datagrid('selectRow',rowIndex);	
		}
	});

	var lastIndex;
	$('#fxblist').datagrid({
		fit: true,
		title:'',
		nowrap: false,
		striped: true,
		singleSelect: true,  
		frozenColumns: [[   
		   {field:'TITLENAME',title:'类型',width:60,sortable:true},
		]],
		columns: [[
			{field:'SC',title:'累计时间（小时）',width:120,sortable:true},
			{field:'BL',title:'占总上网时间比重',width:120,sortable:true},
			{field:'FX',title:'相关分析及建议',width:460,sortable:true,editor:'text'}
		]],
		rownumbers: true,
		onClickRow:function(rowIndex, rowData) {
			if (lastIndex != rowIndex){
				$('#fxblist').datagrid('endEdit', lastIndex);
				$('#fxblist').datagrid('beginEdit', rowIndex);
			}
			lastIndex = rowIndex;
		}
	});
}); 


function fqYcRecordFunc(value ){
	if(value==''){
		$.messager.alert('提示', "请输入会员编码" , 'info');
		return;
	}
	begin = $("#browseBegin").datebox("getValue");
	end = $("#browseEnd").datebox("getValue");
	$.ajax({
		url: '<c:url value="/system/record/recordCXqx.do"/>',
		type: 'POST',
		data: 'usercode='+value ,
		beforeSend: function(XmlHttpRequest, textStatus, errorThrown) {
			$.messager.progress({
				title:'提示',
				msg:'正在执行数据操作，请稍待...'
			});
		},
		success: function(result) {
			$.messager.progress('close');
			if(result.success!='true') {
				$.messager.alert('提示', result.data , 'info');
			}
			else {
				userCode = value;
				if(begin==''){
					$.messager.alert('提示', "请输入起始时间" , 'info');
					return;
				}
				if(end==''){
					$.messager.alert('提示', "请输入截止时间" , 'info');
					return;
				}
				$('#recordYcList').datagrid('getPager').pagination({pageNumber:1}); 
				$('#recordYcList').datagrid('options').url = '<c:url value="/system/record/recordYcList.do"/>?usercode='+value+'&begin='+begin+'&end='+end;
				$("#recordYcList").datagrid('reload');
				$('#fxblist').datagrid('getPager').pagination({pageNumber:1});
				$('#fxblist').datagrid('options').url = '<c:url value="/system/record/recordFxb.do"/>?usercode='+value+'&begin='+begin+'&end='+end;
				$("#fxblist").datagrid('reload');
			}
		}
	});
}

function exprotData(){ 
	//$('#fxblist').datagrid('acceptChanges');
	var fxbList = $('#fxblist').datagrid('getRows');
	var YcList = $('#recordYcList').datagrid('getRows');
	if(fxbList==''||recordYcList==''){
		$.messager.alert('提示', '无信息导出！', 'info'); 
		return;
	}
	
	//var fxb = json2str(fxbList); 
	var url = '<c:url value="/system/record/exportYcRecord.do"/>?userCode='+userCode+'&begin='+begin+'&end='+end;
	//self.location.href = url;
		$.ajax({
		url: url,
		type: 'POST', 
		beforeSend: function(XmlHttpRequest, textStatus, errorThrown) {
			$.messager.progress({
				title:'提示',
				msg:'正在执行数据操作，请稍待...'
			});
		},
		success: function(result) {
			$.messager.progress('close');
			if(!result.success) {
				$.messager.alert('错误', result.data , 'error');
			}
			else {
				$.messager.alert('提示', result.data , 'info');		
				$('#recordList').datagrid('clearSelections').datagrid('reload');
			}
		}
	});
}

function json2str(o) {
	var arr = [];
	var fmt = function(s) {
		if (typeof s == 'object' && s != null) {
			return json2str(s);
		}
		return /^(string|number)$/.test(typeof s) ? "'" + s + "'" : s;
	}
	for (var i in o){
		if(fmt(o[i])!=undefined) {
			arr.push("'" + i + "':" + fmt(o[i]));
		}
	}
	return '{' + arr.join(',') + '}';
}
</script>  

<div class="easyui-layout" fit="true" style="width:100%;height:100%;" >
   <div  region="north" style="height:40px;padding:0px;">
		<table> 
			<tr>
				<td>起始时间：<input id="browseBegin" name="browseBegin" class="easyui-datebox" required="required"></input> </td>
				<td>截止时间：<input id="browseEnd" name="browseEnd" class="easyui-datebox" required="required"></input> </td>
				<td>
					<input id="fqYcRecordBox" class="easyui-searchbox" style="width:220px" menu="#fqYcRecordItem" searcher="fqYcRecordFunc" prompt="请输入查询内容"></input>
					<div id="fqYcRecordItem" style="width:110px;">
						<div name="usercord">会员ID</div> 
					</div> 
				</td>
				<td  style="height:30px;"> 
					<a href="#" id="outxls" iconCls="icon-mail" class="easyui-linkbutton">发送邮件</a>
				</td>
			</tr>
		</table>
	</div>
	<div region="center" style="padding:1px;">
		<table id="recordYcList" > </table>
	</div>
	<div region="south" style="height:200px;padding:1px;">
		<table  id="fxblist"  >  </table> 
	</div> 
</div>
 
